package com.cheyun.netsalev3.repository.aftersale

import com.cheyun.netsalev3.bean.DaoDianDetailsParam
import com.cheyun.netsalev3.bean.aftersale.MaintenanceDetail
import com.cheyun.netsalev3.bean.basedata.Member
import com.cheyun.netsalev3.bean.drive.ReserveInfo
import com.cheyun.netsalev3.bean.order.OrderKeliuData
import com.cheyun.netsalev3.utils.CommonFunc
import com.cheyun.netsalev3.utils.api.ApiCallback
import com.cheyun.netsalev3.utils.api.ApiClient
import com.cheyun.netsalev3.utils.api.ApiException
import com.cheyun.netsalev3.utils.api.BaseResp
import com.google.gson.Gson
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import java.util.*

class EditMaintenanceRepository {
    fun updateData(data: MaintenanceDetail, onSuccess: () -> Unit) {
        var json = Gson().toJson(data)
        var map = CommonFunc.gson.fromJson<TreeMap<String, String>>(json, CommonFunc.typeToken)
        ApiClient.getInstance().editMaintenance(map)
                .subscribeOn(Schedulers.io())
                .subscribeOn(AndroidSchedulers.mainThread())
                .subscribe(object : ApiCallback<BaseResp<Any>>() {
                    override fun onSuccess(t: BaseResp<Any>) {
                        onSuccess()
                    }

                    override fun onError(ex: ApiException) {

                    }


                })
    }


    fun getAftersaleUsableUserList(onSuccess: (data :List<Member>) -> Unit) {
        ApiClient.getInstance().getAftersaleUsableUserList()
                .subscribeOn(Schedulers.io())
                .subscribeOn(AndroidSchedulers.mainThread())
                .subscribe(object : ApiCallback<BaseResp<List<Member>>>() {
                    override fun onSuccess(t: BaseResp<List<Member>>) {
                        onSuccess(t.data!!)
                    }

                    override fun onError(ex: ApiException) {

                    }


                })
    }







}